# GUIdemo10.py
# Demo10 of GUI by PyQt5 (treeWidget)
# Copyright 2021 youcans, XUPT
# Crated：2021-10-20

import sys, math, sip
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
from uiDemo10 import Ui_MainWindow  # 导入 uiDemo10.py 中的 Ui_MainWindow 界面类

class MyMainWindow(QMainWindow, Ui_MainWindow):  # 继承 QMainWindow 类和 Ui_MainWindow 界面类
    def __init__(self, parent=None):
        super(MyMainWindow, self).__init__(parent)  # 初始化父类
        self.setupUi(self)  # 继承 Ui_MainWindow 界面类

        self.treeWidget.itemClicked.connect(self.click_treeWidget)  # 点击 treeWidget 触发

    def click_treeWidget(self, item, column):  # 点击 treeWidget 触发
        # item = self.treeWidget.currentItem()  # 获得当前项 Item
        # if item != None:  # 根据 item 选择执行其它操作

        print('key = {}\tvalue = {}'.format(item.text(0), item.text(1)))
        self.plainTextEdit.appendPlainText("Click: treeWidget")
        self.plainTextEdit.appendPlainText("  key ：{}".format(item.text(0)))


if __name__ == '__main__':
    app = QApplication(sys.argv)  # 在 QApplication 方法中使用，创建应用程序对象
    myWin = MyMainWindow()  # 实例化 MyMainWindow 类，创建主窗口
    myWin.show()  # 在桌面显示控件 myWin
    sys.exit(app.exec_())  # 结束进程，退出程序
